<?php

class StaffManageController extends AdminController {

    public function actionView() {
        $page = isset($_GET['p']) ? $_GET['p'] : 1;
        $dataPerpage = 10;
        if(isset($_GET['Keyword']) || isset($_GET['StaffID']) || isset($_GET['Province'])){
            $Keyword = $_GET['Keyword'];
            $StaffID = $_GET['StaffID'];
            $Province = $_GET['Province'];
            $jobseekerList = JobSeeker::getJobseekerListByKeyword($Keyword, $StaffID, $Province, $page, $dataPerpage, true);
        } else {
            $jobseekerList = JobSeeker::getJobseekerList($page, $dataPerpage, true);
        }
        $this->render('staff', array('data' => $jobseekerList, 'page' => $page, 'dataPerpage' => $dataPerpage));
    }

    public function actionStatus() {
        if (isset($_POST)) {
            $StaffID = $_POST['StaffID'];
            $Status = $_POST['Status'];
            echo JobSeeker::editStatusJobSeeker($StaffID, $Status);
        }
    }

    public function actionForm() {
        $StaffID = isset($_GET['staffID']) ? $_GET['staffID'] : '';
        $dataStaff = isset($_GET['staffID']) ? JobSeeker::getDetailJobseeker($StaffID) : array();
        $this->render('applicationform', array('dataStaff' => $dataStaff, "province" => GM::getProvince('en'))
        );
    }

    public function actionDelete() {
        if (isset($_POST)) {
            $StaffID = $_POST['StaffID'];
            JobSeeker::deleteJobseeker($StaffID);
        }
        $this->redirect("index.php?r=StaffManage/view&p={$_POST['p']}");
    }

    public function actionSave() {
        if (isset($_POST)) {
            $StaffID = $_POST['StaffID'];
            $StaffName = $_POST['Name'];
            $Gender = $_POST['Gender'];
            $Nationality = $_POST['Nationality'];
            $DOB = $_POST['DOB'];
            $Address = $_POST['Address'];
            $ProvinceID = $_POST['Province'];
            $ZipCode = $_POST['ZipCode'];
            $Email = $_POST['Email'];
            $Phone = $_POST['Phone'];
            $Mobile = $_POST['Mobile'];
            $Education = $_POST['Education'];
            $Institution = $_POST['Institution'];
            $Major = $_POST['Major'];
            $EnSkill = $_POST['EnSkill'];
            $JpSkill = $_POST['JpSkill'];
            $WorkPosition = $_POST['WorkPosition'];
            $WorkExperienceDetail = $_POST['WorkExperienceDetail'];
            $ExpectWorkingPosition = $_POST['ExpectWorkingPosition'];
            $ExpectWorkingLocation = $_POST['ExpectWorkingLocation'];
            $ExpectSalary = $_POST['ExpectSalary'];
            $Note = $_POST['Note'];
            $JobID = $_POST['JobID'];
            $PageLanguage = $_POST['lang'];
            if ($StaffID == '') {
                JobSeeker::insertJobseeker($StaffName, $Gender, $Nationality, $DOB, $Address, $ProvinceID, $ZipCode, $Email, $Phone, $Mobile, $Education, $Institution, $Major, $EnSkill, $JpSkill, $WorkPosition, $WorkExperienceDetail, $ExpectWorkingPosition, $ExpectWorkingLocation, $ExpectSalary, $Note, $JobID, $PageLanguage, 'P');
            } else {
                JobSeeker::updateJobseeker($StaffID, $StaffName, $Gender, $Nationality, $DOB, $Address, $ProvinceID, $ZipCode, $Email, $Phone, $Mobile, $Education, $Institution, $Major, $EnSkill, $JpSkill, $WorkPosition, $WorkExperienceDetail, $ExpectWorkingPosition, $ExpectWorkingLocation, $ExpectSalary, $Note, $JobID, $PageLanguage);
            }
        }
        $this->actionView();
    }
    
    public function actionGetDatailJob() {
        if (isset($_POST)) {
            $JobID = $_POST['JobID'];
            $lang =$_POST['Lang'];
            echo json_encode(JobsManage::GetInfoByID($JobID,$lang));
        }
    }

}

?>
